<template>
	<view>
		<view class="fireworks">
			<Cat :screenWidth='screenWidth'></Cat>
		</view>
		<!-- <view class="">
			登录中...
		</view> -->
	</view>
</template>

<script>
	import Cat from '@/pages/vuepress-plugin-cat/cat.vue'
	import {
		store,
		mutations
	} from '@/uni_modules/uni-id-pages/common/store.js'
	export default {
		components: {
			Cat
		},
		data() {
			return {
				screenWidth:0,
				screenHeight:0,
				statusBarHeight:0,
				windowWidth:0,
				screenTop:0,
				platform:'',
				widthRatio:0,
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: e => {
					console.log('系统信息', e);
					this.statusBarHeight = e.statusBarHeight;
					this.screenHeight = e.screenHeight;
					this.screenWidth = e.screenWidth;
					this.platform = e.platform;
					this.widthRatio = e.screenWidth / 750;

					this.windowWidth = e.windowWidth;
					this.screenTop = e.screenTop;
				}
			})
		},
		computed:{
			gridWidth(){
				// 向下取整
				return Math.floor(this.screenWidth / 30)
			},
			gridHeight(){
				// 向下取整
				return Math.floor((this.screenHeight  - this.screenTop) / 30)
			}
		},
		onShow() {
			this.autoLogin()
		},
		methods: {
			autoLogin() {
				let type = 'weixin'
				uni.login({
					"provider": type,
					"onlyAuthorize": true,
					success: async e => {
						console.log('type登录2', type);
						this.login(type == 'weixin' ? {
							code: e.code
						} : e.authResult, type)
						uni.hideLoading()
					},
					fail: async (err) => {
						console.log(err);
						uni.hideLoading()
					}
				})
			},
			login(params, type) { //联网验证登录
				// console.log('执行登录开始----');
				console.log({
					params,
					type
				});
				//toLowerCase
				let action = 'loginBy' + type.trim().replace(type[0], type[0].toUpperCase())
				const uniIdCo = uniCloud.importObject("uni-id-co", {
					customUI: true
				})
				uniIdCo[action](params).then(result => {
						uni.showToast({
							title: '登录成功',
							icon: 'none',
							duration: 2000
						});
						// #ifdef H5
						result.loginType = type
						// #endif
						mutations.loginSuccess(result)
						console.log('登录成功',result);
					})
					.catch(e => {
						uni.showModal({
							content: e.message,
							confirmText: "知道了",
							showCancel: false
						});
					})
					.finally(e => {
						uni.hideLoading()
					})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.fireworks {
		width: 100vw;
		height: 100vh;
		
	}

	// @grid: 30 / 60vmin noclip;
	// border-radius: 50%;
	// background: hsl(@y(* -12), 80%, 60%);
	// background: lch(90, 120, @y(*10deg));
	// animation: f @once.p(5s, 7.5s) ease infinite;
	// animation-delay: $s(-90/@I*@i(-1)*@x/@y);


</style>